﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tingjian.gas.service.BaseReponse;
using Tingjian.gas.service.Controllers;
using Tingjian.gas.service.Product.CreateDto;
using Tingjian.gas.service.Product.GetDto;
using Tingjian.gas.service.Product.UpdateDto;
using Volo.Abp.Application.Dtos;
using Volo.Abp.AspNetCore.Mvc;

namespace Tingjian.gas.service.Product
{

    /// <summary>
    /// 设备管理服务
    /// </summary>
    [Route("api/[controller]")]
    public class ProductController : serviceController
    {

        private readonly IProductAppService _productAppService;

        public ProductController(IProductAppService productAppService)
        {
            _productAppService= productAppService;
        }


        /// <summary>
        /// 设备列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("productlist")]
        public async Task<BaseResultModel<PagedResultDto<GetGasMeterDto>>> GetListPagedAsync([FromBody] GetListQueryDto input)
        {
            return BaseResultModel.Succeed(ReturnCode.Success, await _productAppService.GetListPagedAsync(input));
        }

        /// <summary>
        /// 单个设备信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("{id}")]
        public async Task<BaseResultModel<GetGasMeterDto>> GetProductDetailAsync(long id)
        {
            return BaseResultModel.Succeed(ReturnCode.Success, await _productAppService.GetAsync(id));
        }




        [HttpPost("productcreate/pushRedisList")]
        public async Task<BaseResultModel<bool>> AddListInRedsi([FromBody] CreateGasMeterDto input)
        {
            return BaseResultModel.Succeed(ReturnCode.Success, await _productAppService.AddListInRedsi(input));
        }

        /// <summary>
        /// 设备添加
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("productcreate")]
        public async Task<BaseResultModel<long>> Create([FromBody] CreateGasMeterDto input)
        {
            return BaseResultModel.Succeed(ReturnCode.Success, await _productAppService.CreateAsync(input));
        }


        /// <summary>
        /// 设备编辑
        /// </summary>
        /// <param name="id"></param>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut("{id}")]
        public async Task<BaseResultModel<long>> UpdateAsync(long id, [FromBody] UpdateGasMeterDto input)
        {
            return BaseResultModel.Succeed(ReturnCode.Success, await _productAppService.UpdateAsync(id, input));
        }

        /// <summary>
        /// 删除设备
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete("{id}")]
        public async Task<BaseResultModel<bool>> DeleteAsync(long id)
        {
            return BaseResultModel.Succeed(ReturnCode.Success, await _productAppService.DeleteAsync(id));
        }
    }
}
